package com.dhcc.sds.base.controller;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.annotion.CacheClear;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.base.entity.SdcBaseAssessmenlinkEntity;
import com.dhcc.sds.base.cache.formitem.IFormItemCache;
import com.dhcc.sds.base.cache.formitemdic.IFormItemDicCache;
import com.dhcc.sds.base.cache.formitemmatchrule.IFormItemMatchRuleCache;
import com.dhcc.sds.base.entity.SdsQcentityEntity;
import com.dhcc.sds.base.entity.SdsQcfitemDicEntity;
import com.dhcc.sds.base.entity.SdsQcfitemMatchRuleEntity;
import com.dhcc.sds.base.entity.SdsQcformItemEntity;
import com.dhcc.sds.base.service.*;
import com.dhcc.sds.standard.entity.SdsStandDicsubEntity;
import com.dhcc.sds.standard.service.ISdsStandDicsubService;
import com.dhcc.sds.standard.service.ISdsStandSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * 表单项目表
 *
 * @ClassName: SdsQcformItemController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-03-22 10:10:46
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsqcformitem")
public class SdsQcformItemController extends BaseController {

	private String PREFIX = "/backend/sds/sdsqcformitem/";

	@Autowired
	private ISdsQcformItemService sdsQcformItemService;
	@Autowired
    private ISdsCommonService sdsCommonService;
	@Autowired
    private ISdsStandSourceService sdsStandSourceService;
	@Autowired
    private ISdsStandDicsubService sdsStandDicsubService;
	@Autowired
    private ISdsQcentityService sdsQcentityService;
	@Autowired
    private ISdsQcfitemDicService sdsQcfitemDicService;
	@Autowired
    private ISdsQcfitemMatchRuleService sdsQcfitemMatchRuleService;
 

    /**
     * 跳转到表单项目表列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsqcformitem.html";
    }

    /**
     * 跳转到新增表单项目表
     */
    @RequestMapping("/to_add")
    public String toAdd(Model model) {
        // 项目类型
        JSONObject typeMap = sdsCommonService.getDicMap("ItemType");
        // 上传类型
        JSONObject upTypeMap = sdsCommonService.getDicMap("UpType");
        // 质控时机
        JSONObject tipMap = sdsCommonService.getDicMap("ItemTip");
        // 项目数据采集时机
        JSONObject getValTimeMap = sdsCommonService.getDicMap("ItemGetValTime");
        // 数据源
        JSONObject standSourceMap = sdsStandSourceService.getSourceMap();
        // 校验级别
        JSONArray controlLevels = sdsCommonService.getDicArray("ControlLevel");
        // 校验函数
        JSONArray controlExps = sdsCommonService.findExps("ValiRule");
        // 评分表
        JSONObject asmtMap = sdsCommonService.getAsmtMap();

        model.addAttribute("typeMap", typeMap);
        model.addAttribute("upTypeMap", upTypeMap);
        model.addAttribute("tipMap", tipMap);
        model.addAttribute("getValTimeMap", getValTimeMap);
        model.addAttribute("standSourceMap", standSourceMap);
        model.addAttribute("controlLevels", controlLevels);
        model.addAttribute("controlExps", controlExps);
        model.addAttribute("asmtMap", asmtMap);

        return PREFIX + "sdsqcformitem_add.html";
    }

	/**
     * 跳转到修改表单项目表
     */
    @RequestMapping("/to_update/{sdsQcformItemId}")
    public String toUpdate(@PathVariable Long sdsQcformItemId, Model model) {
        SdsQcformItemEntity sdsQcformItem = this.sdsQcformItemService.getInfoById(sdsQcformItemId);
        // 项目类型
        JSONObject typeMap = sdsCommonService.getDicMap("ItemType");
        // 上传类型
        JSONObject upTypeMap = sdsCommonService.getDicMap("UpType");
        // 质控时机
        JSONObject tipMap = sdsCommonService.getDicMap("ItemTip");
        // 项目数据采集时机
        JSONObject getValTimeMap = sdsCommonService.getDicMap("ItemGetValTime");
        // 数据源
        JSONObject standSourceMap = sdsStandSourceService.getSourceMap();
        // 校验级别
        JSONArray controlLevels = sdsCommonService.getDicArray("ControlLevel");
        // 校验函数
        JSONArray controlExps = sdsCommonService.findExps("ValiRule");
        // 评分表
        JSONObject asmtMap = sdsCommonService.getAsmtMap();

        model.addAttribute("typeMap", typeMap);
        model.addAttribute("upTypeMap", upTypeMap);
        model.addAttribute("tipMap", tipMap);
        model.addAttribute("getValTimeMap", getValTimeMap);
        model.addAttribute("standSourceMap", standSourceMap);
        model.addAttribute("sdsQcformItem",sdsQcformItem);
        model.addAttribute("controlLevels", controlLevels);
        model.addAttribute("controlExps", controlExps);
        model.addAttribute("asmtMap", asmtMap);

        return PREFIX + "sdsqcformitem_edit.html";
    }

    /**
     * 获取表单项目表列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
        Page<SdsQcformItemEntity> page = new PageFactory<SdsQcformItemEntity>().defaultPage();
        List<SdsQcformItemEntity> result = this.sdsQcformItemService.page(page, params);
        page.setRecords((List<SdsQcformItemEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增表单项目表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdsQcformItemEntity sdsQcformItem) {
        if (CommonUtil.isOneEmpty(sdsQcformItem)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        try {
            sdsQcformItem.setTriggerExp(java.net.URLDecoder.decode(sdsQcformItem.getTriggerExp(), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        sdsQcformItem.setUpdateFlag(1);
        sdsQcformItem.insert();

        if (CommonUtil.isNotEmpty(sdsQcformItem.getAsmtLinkId())) {
            // 增加关联评分表
            SdcBaseAssessmenlinkEntity sdcBaseAssessmenlink = new SdcBaseAssessmenlinkEntity();
            sdcBaseAssessmenlink.setItemId(sdsQcformItem.getId());
            sdcBaseAssessmenlink.setAsmtId(sdsQcformItem.getAsmtLinkId());
            sdcBaseAssessmenlink.insert();
        }
        return R.ok(sdsQcformItem.getId().toString());
    }

    /**
     * 删除表单项目表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @CacheClear(IFormItemCache.CACHE_NAME)
    public Object delete(@RequestParam Long sdsQcformItemId) {

        this.sdsQcformItemService.deleteById(sdsQcformItemId);

        return R.ok();
    }

    /**
     * 修改表单项目表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @CacheClear(IFormItemCache.CACHE_NAME)
    public Object update(SdsQcformItemEntity sdsQcformItem) {
        if (CommonUtil.isOneEmpty(sdsQcformItem)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdsQcformItemEntity old = this.sdsQcformItemService.selectById(sdsQcformItem.getId());

        old.setEntityId(sdsQcformItem.getEntityId());
        old.setBtCode(sdsQcformItem.getBtCode());
        old.setBtDesc(sdsQcformItem.getBtDesc());
        old.setBtType(sdsQcformItem.getBtType());
        old.setBtUpType(sdsQcformItem.getBtUpType());
        old.setBtItemCat(sdsQcformItem.getBtItemCat());
        old.setBtItemSubCat(sdsQcformItem.getBtItemSubCat());
        try {
            old.setTriggerExp(java.net.URLDecoder.decode(sdsQcformItem.getTriggerExp(), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        old.setCheckTiming(sdsQcformItem.getCheckTiming());
        old.setBtTips(sdsQcformItem.getBtTips());
        old.setBtResume(sdsQcformItem.getBtResume());
        old.setBtIsActive(sdsQcformItem.getBtIsActive());
        old.setBtIsNeeded(sdsQcformItem.getBtIsNeeded());
        old.setBtIndNo(sdsQcformItem.getBtIndNo());
        old.setUpdateUser(sdsQcformItem.getUpdateUser());
        old.setUpdateFlag(1);
        old.updateAllColumnById();

        if (CommonUtil.isEmpty(sdsQcformItem.getAsmtLinkId())) {
            SdcBaseAssessmenlinkEntity sdcBaseAssessmenlink = new SdcBaseAssessmenlinkEntity();
            Wrapper<SdcBaseAssessmenlinkEntity> wpr = new EntityWrapper<>();
            wpr.eq("item_id", sdsQcformItem.getId());
            sdcBaseAssessmenlink.delete(wpr);
        } else {
            SdcBaseAssessmenlinkEntity oldLink = new SdcBaseAssessmenlinkEntity();
            Wrapper<SdcBaseAssessmenlinkEntity> wpr = new EntityWrapper<>();
            wpr.eq("item_id", sdsQcformItem.getId());
            oldLink = oldLink.selectOne(wpr);
            if (CommonUtil.isEmpty(oldLink)) {
                SdcBaseAssessmenlinkEntity sdcBaseAssessmenlink = new SdcBaseAssessmenlinkEntity();
                sdcBaseAssessmenlink.setItemId(sdsQcformItem.getId());
                sdcBaseAssessmenlink.setAsmtId(sdsQcformItem.getAsmtLinkId());
                sdcBaseAssessmenlink.insert();
            } else {
                oldLink.setAsmtId(sdsQcformItem.getAsmtLinkId());
                oldLink.updateAllColumnById();
            }
        }
        return R.ok();
    }

    /**
     * 修改表单项目置为无效
     */
    @RequestMapping(value = "/setInvalidStatus")
    @ResponseBody
    @CacheClear(IFormItemCache.CACHE_NAME)
    public Object setInvalidStatus(@RequestParam Long sdsQcformItemId) {
        SdsQcformItemEntity entity = new SdsQcformItemEntity();
        entity.setId(sdsQcformItemId);
        entity.setBtIsActive(0);
        entity.setUpdateFlag(1);
        this.sdsQcformItemService.updateById(entity);
        return R.ok();
    }

    @RequestMapping(value = "/getSourceFieldAndStandDic")
    @ResponseBody
    public Object getSourceFieldAndStandDic(@RequestParam Long sourceId, @RequestParam(required = false) Long linkStandSubId){
        //输出字段列表
        JSONArray fieldMap = sdsQcformItemService.getSourceFieldMap(sourceId, linkStandSubId);
        //标准字典列表
        JSONArray stanDicMap = sdsQcformItemService.getDicMapBySourceId(sourceId);
        Map result = new HashMap();
        result.put("fieldMap",fieldMap.toJSONString());
        result.put("stanDicMap",stanDicMap.toJSONString());
        return result;
    }

    @RequestMapping(value = "/getStandDicSubList")
    @ResponseBody
    public Object getStandDicSubList(@RequestParam Long dicId){
        Map<String, Object> map = new HashMap<>();
        map.put("dicId",dicId);
        List<SdsStandDicsubEntity> SdsStandDicsubEntities = sdsStandDicsubService.list(map);

        JSONArray array = new JSONArray();
        for (SdsStandDicsubEntity entity : SdsStandDicsubEntities) {
            JSONObject obj = new JSONObject();
            obj.put("value", entity.getId().toString());
            obj.put("text", entity.getDicDesc());
            array.add(obj);
        }
        return array.toJSONString();
    }

    /**
     * 生成表单模板
     */
    @RequestMapping(value = "/creatFormHtmlField")
    @ResponseBody
    public Object creatFormHtmlField(@RequestParam Long entityId){
        return this.sdsQcformItemService.creatFormHtml(entityId);
    }

    /**
     * 生成表单模板
     */
    @RequestMapping(value = "/creatAllFormHtmlField")
    @ResponseBody
    public Object creatAllFormHtmlField(){
        Long entityTypeId = sdsCommonService.getDictId("QcentityType","Up");
        List<SdsQcentityEntity> entityList = sdsQcentityService.selectList(new EntityWrapper<SdsQcentityEntity>().eq("entity_type_id",entityTypeId).eq("is_active" , 1));
        for (SdsQcentityEntity qcentityEntity : entityList) {
            String filename = this.sdsQcformItemService.creatFormHtml(qcentityEntity.getId());
        }
        return R.ok();
    }

    /**
     * 跳转到新增表单项目表
     */
    @RequestMapping("/to_form/{fileName}")
    public String toAdd(@PathVariable String fileName, Model model) {
        model.addAttribute("mrListId", 0);
        model.addAttribute("checkPerm", 1);
        return "/backend/sds/sdsqcformshow/" + fileName;
    }

    @RequestMapping(value = "/getFormUpdateSta")
    @ResponseBody
    public Object getFormUpdateSta(@RequestParam Long entityId){
        Wrapper<SdsQcformItemEntity> wrapper = new EntityWrapper<>();
        wrapper.eq("entity_id", entityId);
        wrapper.eq("update_flag", 1);
        return sdsQcformItemService.selectCount(wrapper);
    }

    /**
     * 导出病种
     */
    @RequestMapping("/export")
    public void export(@RequestParam(required = false) String entityId,
                            HttpServletRequest request,
                            HttpServletResponse response) {

        // 获取病种信息
        SdsQcentityEntity qcEntity = this.sdsQcentityService.selectById(entityId);
        // 查询病种项目
        Map params = new HashMap();
        params.put("entityId", entityId);
        List<SdsQcformItemEntity> formItems = this.sdsQcformItemService.list(params);
        // 查询病种值域字典
        List<SdsQcfitemDicEntity> formItemDics = new ArrayList<>();
        // 查询病种项目校验
        List<SdsQcfitemMatchRuleEntity> formItemMatchRules = new ArrayList<>();

        // 通过工具类创建writer，默认创建xls格式
        BigExcelWriter writer = (BigExcelWriter) ExcelUtil.getBigWriter();
        // 重命名第一个Sheet的名称，不然会默认多出一个Sheet1的页
        writer.renameSheet("项目");
        // 一次性写出内容，使用默认样式
        if (CommonUtil.isNotEmpty(formItems)) {
            ArrayList<Map<String, Object>> rows = CollUtil.newArrayList();
            int i = 0;
            for (SdsQcformItemEntity obj : formItems) {
                Map<String, Object> row = new LinkedHashMap<>();
                row.put("序号", obj.getBtIndNo());
                row.put("病种", qcEntity.getAbbrev());
                row.put("项目代码", obj.getBtCode());
                row.put("项目名称", obj.getBtDesc());
                row.put("大类", obj.getBtItemCat());
                row.put("子类", obj.getBtItemSubCat());
                row.put("上传类型", obj.getBtUpType()!=null?obj.getBtUpTypeDict().getDescription():"");
                row.put("是否必填", obj.getBtIsNeeded()!=0?"是":"否");
                row.put("前置条件", obj.getTriggerExp());
                row.put("是否有效", obj.getBtIsActive()!=0?"是":"否");
                row.put("项目类型", obj.getBtType()!=null?obj.getBtTypeDict().getDescription():"");
                row.put("质控时机", obj.getCheckTiming()!=null?obj.getCheckTimDict().getDescription():"");
                row.put("质控提示", obj.getBtTips());
                row.put("项目备注", obj.getBtResume());
                rows.add(row);

                // 查询项目值域
                params.put("formItemId", obj.getId());
                List<SdsQcfitemDicEntity> fitemDicSubs = this.sdsQcfitemDicService.list(params);
                if (fitemDicSubs.size()>0) {
                    formItemDics.addAll(fitemDicSubs);
                }
                // 查询项目校验规则
                List<SdsQcfitemMatchRuleEntity> fitemMatchRuleSubs = this.sdsQcfitemMatchRuleService.list(params);
                if (fitemMatchRuleSubs.size()>0) {
                    formItemMatchRules.addAll(fitemMatchRuleSubs);
                }
            }
            writer.write(rows);
            writer.setColumnWidth(1, 10);
            writer.setColumnWidth(2, 20);
            writer.setColumnWidth(3, 30);
            writer.setColumnWidth(4, 30);
            writer.setColumnWidth(5, 30);
            writer.setColumnWidth(6, 20);
            writer.setColumnWidth(7, 10);
            writer.setColumnWidth(8, 30);
            writer.setColumnWidth(9, 10);
            writer.setColumnWidth(10, 20);
            writer.setColumnWidth(11, 20);
            writer.setColumnWidth(12, 20);
            writer.setColumnWidth(13, 20);
        } else {
            List<String> row = CollUtil.newArrayList("无数据");
            List<List<String>> rows = new ArrayList<List<String>>();
            rows.add(row);
            writer.write(rows);
        }

        writer.setSheet("值域字典");
        if (CommonUtil.isNotEmpty(formItemDics)) {
            ArrayList<Map<String, Object>> rows = CollUtil.newArrayList();
            for (SdsQcfitemDicEntity obj : formItemDics) {
                Map<String, Object> row = new LinkedHashMap<>();
                row.put("病种", qcEntity.getAbbrev());
                row.put("项目代码", this.sdsQcformItemService.selectById(obj.getFormItemId()).getBtCode());
                row.put("代码", obj.getCode());
                row.put("描述", obj.getDesc());
                row.put("序号", obj.getIndNo());
                //row.put("分组", obj.getGroup());
                row.put("是否默认", obj.getIsDefault()!=0?"是":"否");
                row.put("是否有效", obj.getIsActive()!=0?"是":"否");
                //row.put("项目备注", obj.getResume());
                rows.add(row);
            }
            writer.write(rows);
            writer.setColumnWidth(0, 10);
            writer.setColumnWidth(1, 20);
            writer.setColumnWidth(2, 10);
            writer.setColumnWidth(3, 30);
            writer.setColumnWidth(4, 10);
            writer.setColumnWidth(5, 10);
            writer.setColumnWidth(6, 10);
            //writer.setColumnWidth(7, 10);
            //writer.setColumnWidth(8, 30);
        } else {
            List<String> row = CollUtil.newArrayList("无数据");
            List<List<String>> rows = new ArrayList<List<String>>();
            rows.add(row);
            writer.write(rows);
        }

        writer.setSheet("校验规则");
        if (CommonUtil.isNotEmpty(formItemMatchRules)) {
            ArrayList<Map<String, Object>> rows = CollUtil.newArrayList();
            for (SdsQcfitemMatchRuleEntity obj : formItemMatchRules) {
                Map<String, Object> row = new LinkedHashMap<>();
                row.put("病种", qcEntity.getAbbrev());
                row.put("项目代码", this.sdsQcformItemService.selectById(obj.getFormItemId()).getBtCode());
                row.put("提示内容", obj.getTipText());
                row.put("校验函数", obj.getControlExpId()!=null?obj.getExpDict().getExpCode():"");
                row.put("表达式", obj.getControlExp());
                row.put("校验级别", obj.getControlLevel()!=null?obj.getLevelDict().getCode():"");
                rows.add(row);
            }
            writer.write(rows);
            writer.setColumnWidth(0, 10);
            writer.setColumnWidth(1, 20);
            writer.setColumnWidth(2, 40);
            writer.setColumnWidth(3, 30);
            writer.setColumnWidth(4, 40);
            writer.setColumnWidth(5, 20);
        } else {
            List<String> row = CollUtil.newArrayList("无数据");
            List<List<String>> rows = new ArrayList<List<String>>();
            rows.add(row);
            writer.write(rows);
        }

        ServletOutputStream out = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            String fileName = qcEntity.getAbbrev()+"_" + sdf.format(new Date()) + ".xlsx";
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String(fileName.getBytes("GBK"), "ISO8859_1"));
            out = response.getOutputStream();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            writer.flush(out);
            // 关闭writer，释放内存
            writer.close();
        }
    }

    /**
     * 跳转到导入病种的页面
     */
    @RequestMapping("/to_import")
    public String toImport() {
        return PREFIX + "import.html";
    }

    /**
     * 导入病种字典
     */
    @RequestMapping(method = RequestMethod.POST, path = "/import")
    @ResponseBody
    @CacheClear({IFormItemCache.CACHE_NAME,IFormItemDicCache.CACHE_NAME,IFormItemMatchRuleCache.CACHE_NAME})
    public R importItem(@RequestPart("file") MultipartFile file, @RequestPart("entityId") Long entityId) {
        ExcelReader reader;
        try {
            String fileName = file.getOriginalFilename();
            String entityCode = fileName.substring(0, fileName.lastIndexOf(".")); // 文件名：病种代码
            // 获取当前病种信息
            // 获取病种信息
            SdsQcentityEntity qcEntity = this.sdsQcentityService.selectById(entityId);
            if (!entityCode.equalsIgnoreCase(qcEntity.getAbbrev())) {
                return R.error("请确认上传文件是否与当前选择病种一致！");
            }
            reader = ExcelUtil.getReader(file.getInputStream(),0);
            List<List<Object>> itemAll = reader.read();
            this.sdsQcformItemService.importItem(entityId, itemAll);
            reader = ExcelUtil.getReader(file.getInputStream(),1);
            List<List<Object>> dicAll = reader.read();
            this.sdsQcformItemService.importDic(entityId, dicAll);
            reader = ExcelUtil.getReader(file.getInputStream(),2);
            List<List<Object>> ruleAll = reader.read();
            this.sdsQcformItemService.importRule(entityId, ruleAll);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok();
    }

    /**
     * 同步通用项目数据源配置
     */
    @RequestMapping("/syncDataConfig")
    @ResponseBody
    public R syncDataConfig(@RequestParam Long entityId) {
        int count = this.sdsQcformItemService.syncDataConfig(entityId);
        int num = this.sdsQcformItemService.syncItemDefault(entityId);
        return R.ok("同步通用项目数量：" + count + "<br>" + "同步评价默认项信息：" + num);
    }

    /**
     * 同步全部病种通用项目数据源配置
     */
    @RequestMapping("/syncAllDataConfig")
    @ResponseBody
    public R syncAllDataConfig() {
        StringBuilder sb = new StringBuilder();
        Long entityTypeId = sdsCommonService.getDictId("QcentityType","Up");
        List<SdsQcentityEntity> entityList = sdsQcentityService.selectList(new EntityWrapper<SdsQcentityEntity>().eq("entity_type_id",entityTypeId).eq("is_active" , 1));
        int entityNum = 0;
        for (SdsQcentityEntity entity : entityList) {
            int count = this.sdsQcformItemService.syncDataConfig(entity.getId());
            sb.append("|-").append(entity.getBtDesc()).append("：").append(count).append("<br>");
            int num = this.sdsQcformItemService.syncItemDefault(entity.getId());
            if (num > 0) {
                entityNum++;
            }
        }
        sb.append("成功同步【").append(entityNum).append("】个病种评价默认项信息！");
        return R.ok(sb.toString());
    }

}
